package com.lagou.homework.sort;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class SortReducer extends Reducer<IntWritable,NullWritable,IntWritable,IntWritable> {
    //制定输出序号
    private int i=1;
    private IntWritable nkey=new IntWritable();
    //重写reduce方法
    @Override
    protected void reduce(IntWritable key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
      //遍历读取所有values，输出相同的key值
        for (NullWritable value : values) {
            nkey.set(i++);
            context.write(nkey,key);
        }
    }
}
